/*
 * @(#)Xfsp.java        2004/08/01
 *
 * This file is part of Xfuzzy 3.1, a design environment for fuzzy logic
 * based systems.
 *
 * (c) 2000 IMSE-CNM. The authors may be contacted by the email address:
 *                    xfuzzy-team@imse.cnm.es
 *
 * Xfuzzy is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * Xfuzzy is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

package xfuzzy.xfsp;

import java.awt.Point;

import xfuzzy.Xfuzzy;

import xfuzzy.lang.Specification;

import xfuzzy.xfsp.controller.XfspController;
import xfuzzy.xfsp.controller.XfspStore;
import xfuzzy.xfsp.model.XfspModel;
import xfuzzy.xfsp.view.XfspView;

/**
 * <p> <b>Descripci�n:</b> Clase que permite la simplificaci�n de sistemas
 * difusos.
 * <p> <b>E-mail</b>: <ADDRESS>joragupra@us.es</ADDRRESS>
 * @author Jorge Agudo Praena
 * @version 2.3
 * @see XfspEvent
 * @see XfspController
 * @see XfspModel
 * @see XfspStore
 * @see XfspView
 *
 */
public class Xfsp {
  private XfspModel model;
  private XfspController controller;
  private XfspView view;
  private XfspStore store;

  /**
   * <p> <b>Descripci�n:</b> crea una instancia del sistema de simplificaci�n
   * de sistemas difusos.
   * @param xfuzzy Sistema principal desde donde se hace la llamada al sistema
   * de simplificaci�n.
   * @param spec Especificaci�n del sistema difuso a simplificar.
   *
   */
  public Xfsp(Xfuzzy xfuzzy, Specification spec) {

    Specification workingcopy;

    //parser = null;
    this.store = new XfspStore();
    this.model = new XfspModel(xfuzzy, spec, store);

    workingcopy = model.getWorkingcopy();

    this.controller = new XfspController();
    this.controller.init(model, store);

    // nuevo!!
    this.store.addObserver(controller);

    //TODO - quitar estos comentarios

    this.view = new XfspView(store);
    this.view.xfuzzy(true);
    this.view.setParentLocation(xfuzzy.frame.getLocationOnScreen());
    this.view.setTypes(workingcopy.getTypes()); //spec.getTypes());
    this.view.setRuleBases(workingcopy.getRulebases()); //spec.getRulebases());
    this.view.setName(spec.getName());
    this.view.build();
    this.controller.registerView(view);
  }



  /**
   * <p> <b>Descripci�n:</b> crea una instancia del sistema de simplificaci�n
   * de sistemas difusos indicando la localizaci�n que debe ocupar la vista en
   * la pantalla.
   * @param xfuzzy Sistema principal desde donde se hace la llamada al sistema
   * de simplificaci�n.
   * @param spec Especificaci�n del sistema difuso a simplificar.
   * @param location Localizaci�n que ocupar� en la pantalla la vista de la
   * instancia creada.
   *
   */
  public Xfsp(Xfuzzy xfuzzy, Specification spec, Point location) {

    Specification workingcopy;

    this.store = new XfspStore();
    this.model = new XfspModel(xfuzzy, spec, store);

    workingcopy = model.getWorkingcopy();

    this.controller = new XfspController();
    this.controller.init(model, store);

    this.store.addObserver(controller);

    this.view = new XfspView(store);
    this.view.xfuzzy(true);
    this.view.setLocation(location);
    this.view.setTypes(workingcopy.getTypes()); //spec.getTypes());
    this.view.setRuleBases(workingcopy.getRulebases()); //spec.getRulebases());
    this.view.setName(spec.getName());
    this.view.build();
    this.controller.registerView(view);
  }

  /**
   * <p> <b>Descripci�n:</b> muestra en pantalla la vista del sistema de
   * simplificaci�n de sistemas difusos.
   *
   */
  public void show() {
    view.setVisible(true);
  }
}
